/**
 * 
 */
package info.niwota.ezb;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Window;
import android.view.WindowManager;

/**
 * @author qiangli
 * 
 */
public final class Screens {
	// Settings.System.getInt(getContentResolver(),
	// Settings.System.SCREEN_BRIGHTNESS);
	
	public static final float MIN_SCREEN_BRIGHTNESS = 0.01f;  // min without going to sleep
	
	public static final float FULL_SCREEN_BRIGHTNESS = 1.00f;
	
	private Screens() {
	}

	public static void blackout(Activity ctx) {
		setBrightness(ctx, MIN_SCREEN_BRIGHTNESS);
	}

	public static void whitein(Activity ctx) {
		setBrightness(ctx, 1.00f);
	}

	public static void setFullBrightness(Activity ctx) {
		setBrightness(ctx, 1.00f);
	}
	
	public static void setDefaultBrightness(Activity ctx) {
		Window w = ctx.getWindow();
		WindowManager.LayoutParams lp = w.getAttributes();
		lp.screenBrightness = -1f;
		w.setAttributes(lp);
	}
	
	public static void setDimBrightness(Activity ctx) {
		Window w = ctx.getWindow();
		WindowManager.LayoutParams lp = w.getAttributes();
		lp.screenBrightness = MIN_SCREEN_BRIGHTNESS;
		w.setAttributes(lp);
	}

	public static void setBrightness(Activity ctx, float value) {
		if (value < MIN_SCREEN_BRIGHTNESS) {
			value = MIN_SCREEN_BRIGHTNESS; //ensure we wont go too low
		}
		Window w = ctx.getWindow();
		WindowManager.LayoutParams lp = w.getAttributes();
		lp.screenBrightness = value;
		w.setAttributes(lp);
	}

	public static void blackscreen(Activity ctx, int rc) {
		try {
			Intent i = new Intent(ctx, ScreenActivity.class);
			ctx.startActivityForResult(i, rc);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void blackscreen(Context ctx) {
		try {
			Intent i = new Intent(ctx, ScreenActivity.class);
			ctx.startActivity(i);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void setFullDarkness(Activity ctx) {
		setBrightness(ctx, MIN_SCREEN_BRIGHTNESS);
	}
}
